import javax.swing.plaf.synth.SynthOptionPaneUI;

public class project {
    public static void main(String[] args) {
        char[][] ch={{'X','X','X','X'},{'X','O','O','X'},{'X','X','O','X'},{'X','O','X','X'}};
        solve(ch);
        for(int i=0;i<ch.length;i++){
            for(int j=0;j<ch[0].length;j++){
                System.out.print(ch+" ");
            }
            System.out.println();
        }
    }
    public static void solve(char[][] board) {
        int row=board.length;
        int col=board[0].length;
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                boolean bool=i==0||j==0||i==row-1||j==col-1;
                if(bool&&board[i][j]=='O'){
                    dfs2(board,i,j,row,col);
                }
            }
        }
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                if (board[i][j] == 'O') {
                    board[i][j]='X';
                }
                if(board[i][j]=='#'){
                    board[i][j]='O';
                }
            }
        }
    }
    public static void dfs2(char[][] str,int x,int y,int row,int col){
        if(x<0||y<0||x>=row||y>=col||str[x][y]=='X'||str[x][y]=='#'){
            return;
        }
        str[x][y]='#';
        dfs2(str,x-1,y,row,col);
        dfs2(str,x+1,y,row,col);
        dfs2(str,x,y-1,row,col);
        dfs2(str,x,y+1,row,col);
    }




















    public static void main1(String[] args) {
        String s="  hello  world";
        System.out.println(reverseWords(s));
//        String s="ac";
//        String ret=Main.longestPalindrome(s);
//        System.out.println(ret);
    }
    public static String reverseWords(String s) {
        String[] str=s.split(" ");
        StringBuilder sb=new StringBuilder();
        for(int i=str.length-1;i>=0;i--){
            if(str[i].equals("")||str[i].equals(" ")){
                continue;
            }
            sb.append(i==0?str[i]:str[i]+" ");
        }
        if(sb.charAt(sb.length()-1)==' '){
            sb= new StringBuilder(sb.substring(0, sb.length() - 1));
        }
        return sb.toString();
    }
















    public String multiply(String num1, String num2) {
        if(num1.equals("0")||num2.equals("0")){
            return "0";
        }
        String ret="0";
        int len1=num1.length();
        int len2=num2.length();
        for(int i=len2-1;i>=0;i--){
            StringBuilder sb=new StringBuilder();
            int add=0;
            for(int j=len2-1;j>i;j--){
                sb.append(0);
            }
            int y=num2.charAt(i)-'0';
            for(int j=len1-1;j>=0;j--){
                int x=num1.charAt(j)-'0';
                int sum=x*y+add;
                add=sum/10;
                sb.append(sum%10);
            }
            if(add!=0){
                sb.append(add%10);
            }
            ret=addString(ret,sb.reverse().toString());
        }
        return ret;
    }
    public String addString(String num1,String num2){
        int i=num1.length()-1;
        int j=num2.length()-1;
        int add=0;
        StringBuilder sb=new StringBuilder();
        while (i>=0||j>=0||add!=0){
            int x=i>=0?num1.charAt(i)-'0':0;
            int y=j>=0?num2.charAt(j)-'0':0;
            int sum=x+y+add;
            add=sum/10;
            sb.append(sum%10);
            i--;
            j--;
        }
        return sb.reverse().toString();
    }























    public String longestPalindrome(String s) {
        if(s==null||s.length()<1){
            return "";
        }
        int start=0;
        int end=0;
        for(int i=0;i<s.length();i++){
            int left=com(s,i,i);
            int right=com(s,i,i+1);
            int len=Math.max(left,right);
            if(len>end-start){
                start=i-(len-1)/2;
                end=i+len/2;
            }
        }
        return s.substring(start,end+1);
    }
    public int com(String s,int left,int right){
        if(left>=0&&right<s.length()&&s.charAt(left)==s.charAt(right)){
            left--;
            right++;
        }
        return right-left-1;
    }




















    public int[][] imageSmoother(int[][] img) {
        int row=img.length;
        int col=img[0].length;
        int[][] arr=new int[row][col];
        int count=0;
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                count=0;
                for(int curI=i-1;curI<=i+1;curI++){
                    for(int curJ=j-1;curJ<=j+1;curJ++){
                        if(curI>=0&&curI<row&&curJ>=0&&curJ<col){
                            arr[i][j]+=img[curI][curJ];
                            count++;
                        }
                    }
                }
                arr[i][j]/=count;
            }
        }
        return arr;
    }

}
